package com.example.administrator.xiangce;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/11/23.
 */
public class MyAdapter extends BaseAdapter {

    private LayoutInflater layoutInflater;
    private ArrayList<Object>objectArrayList;

    MyAdapter(Context context, ArrayList<Object>list) {
        this.objectArrayList = list;
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return this.objectArrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        Object object = objectArrayList.get(i);
        if(view == null) {
            view = layoutInflater.inflate(R.layout.object,null);
            ImageView imageView = (ImageView)view.findViewById(R.id.imageView);
          // ImageView imageView1 = (ImageView) view.findViewById(R.id.imageView1);
           //ImageView imageView2 = (ImageView) view.findViewById(R.id.imageView2);


            imageView.setImageURI(Uri.parse(object.getTuPian()));
            //imageView1.setImageURI(Uri.parse(object.getZhangShu()));
            //imageView2.setImageURI(Uri.parse(object.getID()));

            MyTag myTag = new MyTag();
            myTag.imageView = imageView;
          // myTag.imageView1 = imageView1;
           //myTag.imageView2 = imageView2;

            view.setTag(myTag);
            return view;

        }else {
            MyTag myTag = (MyTag)view.getTag();
            ImageView imageView = myTag.imageView;
            //ImageView imageView1 = myTag.imageView1;
            //ImageView imageView2 = myTag.imageView2;

            imageView.setImageURI(Uri.parse(object.getTuPian()));
           // imageView1.setImageURI(Uri.parse(object.getZhangShu()));
            //imageView2.setImageURI(Uri.parse(path));

            return view;
        }
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    class MyTag{
        ImageView imageView;
       //ImageView imageView1;
       //ImageView imageView2;
    }
}
